package com.hljx.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hljx.config.Result;
import com.hljx.dto.RolePageDTO;
import com.hljx.dto.SysRoleDTO;
import com.hljx.dto.SysRoleMenuDTO;
import com.hljx.entity.SysMenu;
import com.hljx.service.SysMenuService;
import com.hljx.service.SysRoleService;
import com.hljx.vo.RoleVO;
import com.hljx.vo.SysMenuVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author gx
 * @since 2023-09-25
 */
@RestController
@RequestMapping("/sysRole")
@Tag(name = "角色管理")
public class SysRoleController {

    @Autowired
    SysRoleService sysRoleService;

    @Operation(summary = "新建或更新")
    @PostMapping("/saveOrUpdateNew")
    public Result<Boolean> saveOrUpdateNew(@RequestBody SysRoleDTO sysRoleDTO) {
        return Result.success(sysRoleService.saveOrUpdateNew(sysRoleDTO));
    }

    @Operation(summary = "查询角色列表")
    @PostMapping("/selectRoleList")
    public Result<IPage<RoleVO>> selectRoleList(@RequestBody RolePageDTO rolePageDTO) {
        return Result.success(sysRoleService.selectRoleList(rolePageDTO));
    }

    @Operation(summary = "通过id删除")
    @GetMapping("/removeSysRole")
    public Result<Boolean> removeSysRole(@RequestParam("id") Long id) {
        return Result.success(sysRoleService.removeSysRole(id));
    }

    @Operation(summary = "修改角色启用状态")
    @GetMapping("/updateRoleStatus")
    public Result<Boolean> updateRoleStatus(@RequestParam("id") Long id,@RequestParam("status") Integer status) {
        return Result.success(sysRoleService.updateRoleStatus(id,status));
    }

    @Operation(summary = "为角色赋予权限")
    @PostMapping("/addAuthMenu")
    public Result<Boolean> addAuthMenu(@RequestBody SysRoleMenuDTO dto) {
        return Result.success(sysRoleService.addAuthMenu(dto));
    }

    @Operation(summary = "查询选中的菜单ids")
    @GetMapping("/selectMenuId")
    public Result<List<Long>> selectMenuId(@RequestParam("roleId") Long roleId) {
        return Result.success(sysRoleService.selectMenuId(roleId));
    }

}
